<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
 '
 ' Copyright 2007 Liu, Xiaokang <4341322@gmail.com>
 ' Blog <http://www.ioio.name/>
 ' 
 ' This file is part of JOS(Judge Online System).
 ' You can see this project at <http://code.google.com/p/judgeonline/>
 ' 
 ' JOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 ' published by the Free Software Foundation; either revision 3 of the License, or (at your option) any later revision.
 ' 
 ' JOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 ' 
 ' You should have received a copy of the GNU General Public License along with JOS. if not, see
 ' <http://www.gnu.org/licenses/>.
 '
%>
<%Option Explicit%>
<%
	Dim PageTitle
	PageTitle="Ranklist"
%>
<!--#include file="Contest_Header.asp"-->
<div id="Main" style="min-height:400px;background-color:#FFF;">
<div class="StatusRecord" id="StatusRecord">
  <%'Dim Cid
	'If Not isempty(Request.QueryString("Cid")) Then
      'Cid=Request.QueryString("Cid")
	 'End If

  	    Dim Rankr
		conn.Open connstr
		Set Rankr = Server.CreateObject("ADODB.Recordset")
		Rankr.Open "SELECT ROW_NUMBER() OVER (ORDER BY AcNum DESC,PenaltyAll ASC) AS RankNum,[Uid],[Cid],[AcNum],[PenaltyAll]  FROM [Contest_Rank] WHERE Cid="+Cid+" ORDER BY AcNum DESC",conn,1,3 
		
		Dim ProNumRS,ProNum
'		Set ProNumRS = Server.CreateObject("ADODB.Recordset")
'		ProNumRS.Open "SELECT COUNT( [Pid]) as ProNum FROM [Contest_Problems] WHERE Cid="+Cid,conn,1,3 
'		ProNum=ProNumRS("ProNum")
'		ProNumRS.Close
'		set ProNumRS=nothing
		
		Dim ProblemArray(10),j
		j=0
		Set ProNumRS = Server.CreateObject("ADODB.Recordset")
		ProNumRS.Open "SELECT [CPid],[Pid] FROM [Contest_Problems] WHERE Cid="+Cid,conn,1,3 
		Do While Not ProNumRS.eof and Not ProNumRS.Bof
		
		ProblemArray(j)=ProNumRS("Pid")
		'Response.Write ProblemArray(j)&" "
		j=j+1
		ProNumRS.movenext
		Loop
		ProNum=j
		ProNumRS.Close
		set ProNumRS=nothing
		
   %>
    <table border="0" id="RecordList" align="center">
      <tr bgcolor=pink>
        <td>Rank</td>
        <td>Team</td>
        <td>Solved</td>
        <td>Penalty</td>
        <%Dim Order,OrderEnd
		Order=Asc("A")
		OrderEnd=Asc("A")+ProNum
		Do While Order<OrderEnd
		%>
        <td width="60px;"><%=Chr(Order)%>(<%=ProblemArray(Order-65)%>)</td>
        <%
		Order=Order+1
		Loop%>
      </tr>      
	  	  <%
		  Dim i
		  i=0
		  Do While Not Rankr.eof
		  %>
      <tr <% if i mod 2=1 then %>bgcolor=#D7EBFF><%else%>>
	  <%end if
	  i=i+1
	  %>
        <td><%=Rankr("RankNum")%></td>
        <%Dim MemberRs
		Set MemberRs = Server.CreateObject("ADODB.Recordset")
		MemberRs.Open "SELECT Username FROM [Members] WHERE Uid="+CStr(Rankr("Uid")),conn,1,3
	  %>
        <td><!--<a href="User_Status.asp?Uid=<%=Rankr("Uid")%>"><%=MemberRs("Username")%></a>--><%=MemberRs("Username")%></td>
        <%
		MemberRs.Close
		set MemberRs=nothing
		%>
        <td><%=Rankr("AcNum")%></td>
        <td><%		
		Dim seconds,h,m,s,hh,mm,ss,Penalty
		
		seconds=Rankr("PenaltyAll")
		h=int(seconds/3600) 
		m=int((seconds-h*3600)/60)
		s=int(seconds-h*3600-m*60)
		
		IF h<9 Then		
		hh="0"+CStr(h)+":"
		Else
		hh=	CStr(h)+":"	
		End If
		
		IF m<9 Then		
		mm="0"+CStr(m)+":"
		Else
		mm=	CStr(m)+":"		
		End If
		
		IF s<9 Then		
		ss="0"+CStr(s)
		Else
		ss=	CStr(s)		
		End If
				
		Response.Write hh+mm+ss
		%></td>
        <%Dim Pstart,Pend
		Pstart=0
		Pend=ProNum
		Do While Pstart<Pend
		%>
        <td><%
		'Response.Write ProblemArray(Pstart)&": "
		Dim ProNotAcNum
		ProNotAcNum=0
		Set ProNumRS = Server.CreateObject("ADODB.Recordset")
		ProNumRS.Open "SELECT [Penalty],[PenaltyTime] FROM [Contest_Rank_Pid_Penalty] WHERE Cid="+Cid+" AND Uid="+CStr(Rankr("Uid"))+" AND Pid="+CStr(ProblemArray(Pstart)),conn,1,3 
		If Not ProNumRS.eof And Not ProNumRS.Bof Then
		
		'Dim seconds,h,m,s,hh,mm,ss,Penalty
		ProNotAcNum=ProNumRS("Penalty")
		IF Not IsNULL(ProNumRS("PenaltyTime")) Then
		seconds=ProNumRS("PenaltyTime")
		h=int(seconds/3600) 
		m=int((seconds-h*3600)/60)
		s=int(seconds-h*3600-m*60)
		
		IF h<9 Then		
		hh="0"+CStr(h)+":"
		Else
		hh=	CStr(h)+":"	
		End If
		
		IF m<9 Then		
		mm="0"+CStr(m)+":"
		Else
		mm=	CStr(m)+":"		
		End If
		
		IF s<9 Then		
		ss="0"+CStr(s)
		Else
		ss=	CStr(s)		
		End If
				
		Response.Write hh+mm+ss
		
		End If
		
		End If
		
		If ProNotAcNum>0 Then
		Response.Write "(-"+CStr(ProNotAcNum)+")"
		End If
		ProNumRS.Close
		set ProNumRS=nothing
		
		%></td>
        <%
		Pstart=Pstart+1
		Loop%>
      </tr>
	  <% 
	  Rankr.movenext
	  Loop
	  %>
      <tr>
        <td colspan="18">pages</td>
      </tr>
    </table>
	<%
		Rankr.Close
		set Rankr=nothing 
		conn.Close
   %>
   <div>&nbsp;</div>
  </div>
</div>
<!--#include file="Footer.asp"-->